package com.demo.edit.stream;

import com.demo.edit.util.Base64;
import com.saver.office.ISteam;

import java.io.*;

public class LocalSteam implements ISteam {

    public InputStream getSteam(String fileId) {
        String[] s1 = fileId.split("_");
        String s = new String(Base64.decode(s1[0]));
        File file = new File(s);
        FileInputStream inputStream = null;

        try {
            inputStream = new FileInputStream(file);
        } catch (FileNotFoundException var5) {
            var5.printStackTrace();
        }

        return inputStream;
    }

    public void writeSteam(String fileId, InputStream inputStream) {
        String[] s1 = fileId.split("_");
        if (s1[1].equals("false")){
            String s = new String(Base64.decode(s1[0]));
            File file = new File(s);

            try {
                FileOutputStream fileOutputStream = new FileOutputStream(file);
                byte[] buffer = new byte[1024];

                int i;
                while((i = inputStream.read(buffer)) > -1) {
                    fileOutputStream.write(buffer, 0, i);
                }

                fileOutputStream.close();
                inputStream.close();
            } catch (FileNotFoundException var7) {
                var7.printStackTrace();
            } catch (IOException var8) {
                var8.printStackTrace();
            }
        }
    }

}
